package fdq.entity;

import fdq.mapper.FeatureMapper;
import fdq.utils.SqlSessionGet;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;

public class Feature {
    private int fid;
    private String feature;
    private final SqlSessionGet sqlSessionGet = new SqlSessionGet();
    private final SqlSession sqlSession = sqlSessionGet.getSqlsession();
    private FeatureMapper featureMapper = sqlSession.getMapper(FeatureMapper.class);

    public Feature() {
    }

    public Feature(String feature) {
        this.feature = feature;
    }

    public Feature(int fid) {
        this.fid = fid;
        this.feature = featureMapper.selectFeatureByFid(fid);
    }

    public Feature(int fid, String feature) {
        this.fid = fid;
        this.feature = feature;
    }



    public int getFid() {
        return fid;
    }

    public void setFid(int fid) {
        this.fid = fid;
    }

    public String getFeature() {
        return feature;
    }

    public void setFeature(String feature) {
        this.feature = feature;
    }


    //该函数用来判断第二个Feature数组是否包含第一个数组
    static public boolean featureInside(ArrayList<Feature> featureLess, ArrayList<Feature> featuresMore){
        int flag = 0;
        for(Feature a : featureLess){
            for(Feature o : featuresMore){
                if(a.getFid() == o.getFid()){
                    flag += 1;
                }
            }
        }

        if(flag == featureLess.size()){
            return true;
        }else {
            return false;
        }
    }

    public static boolean featureInside(Feature feature, ArrayList<Feature> features) {
        for(Feature f : features){
            if(feature.getFid() == f.getFid()){
                return true;
            }
        }
        return false;
    }


}
